local rule = fk.CreateSkill {
  name = "#role_exmode_rule_mingtu&",
}

Fk:loadTranslationTable {
  ["#role_exmode_rule_mingtu&"] = "命途",
  ["#role_exmode_rule_mingtu_ask"] = "命途：你可以亮出身份，获得 <b>%arg</b>：%arg2",
  ["#role_exmode_rule_mingtu_ex"] = "命途：你可以亮出身份，随机获得一个命途技",
}

--规则
rule:addEffect(fk.Deathed, {
  priority = 0.001,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    --local num = #player.room.players
    --if num / 2 == 0 then num = num + 1 end
    return --(num / 2) >= #player.room.alive_players and 
    player:isAlive() and player.role == "renegade" and not player.role_shown
  end,
  --[[
  on_cost = function (self, event, target, player, data)
    local prompt = "#role_exmode_rule_mingtu&_ex"
    local skill = Fk.skills["role_exmode_mingtu__"..player.kingdom]
    if skill then
      prompt = "#role_exmode_rule_mingtu&_ask:::"..Fk:translate(skill.name)..":"..Fk:translate(":"..skill.name)
    end
    local room = player.room
    local command = "AskForSkillInvoke"
    local req = Request:new(room.alive_players, command, 1)
    req.focus_text = rule.name
    req.receive_decode = false -- 这个返回的都是"1" 不用decode
    req:setData(player, { rule.name, prompt })
    return req:getResult(player) ~= ""
  end,
  --]]
  on_cost = function(self, event, target, player, data)
    local prompt = "#role_exmode_rule_mingtu_ex"
    local skill = Fk.skills["role_exmode_mingtu__" .. player.kingdom]
    if skill then
      prompt = "#role_exmode_rule_mingtu_ask:::" .. Fk:translate(skill.name) .. ":" .. Fk:translate(":" .. skill.name)
    end
    local room = player.room
    return room:askToSkillInvoke(player, { skill_name = rule.name, prompt = prompt })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player.role_shown = true
    room:broadcastProperty(player, "role_shown")
    local list = { "lb_hui", "lb_lie", "lb_shi", "lb_xie", "lb_xu", "lb_feng", "lb_hu", "lb_yi", }
    local kingdom = table.contains(list, player.kingdom) and player.kingdom or table.random(list)
    local skill = Fk.skills["role_exmode_mingtu__" .. kingdom]
    if skill then
      room:handleAddLoseSkills(player, skill.name, nil, false, true)
    end
  end,
})

return rule